package de.reichelt.fx;

import javafx.scene.control.TableColumn;
import javafx.scene.control.cell.PropertyValueFactory;

public class FxTableField {
  private String fieldName;
  private String label;
  private int fieldType; //text, memo, html, int, double, money, date, checkbox, 
  private Double width;
  private TableColumn control;
  private PropertyValueFactory pvf;
  public static int TYPE_TEXT = 1;
  public static int TYPE_MEMO = 2;
  public static int TYPE_HTML = 3;
  public static int TYPE_INT = 4;
  public static int TYPE_DOUBLE = 5;
  public static int TYPE_MONEY = 6;
  public static int TYPE_DATE = 7;
  public static int TYPE_BOOLEAN = 8;
  public static int TYPE_DDATE = 9;
  public static int TYPE_DSTRING = 10;
  
  /**
   * erzeugt ein neues Tabellenfeld.
   * @param fieldName  Name der Spalte, über den das Feld gesucht werden kann; muss genau dem Namen des Feldes im Datenobjekt entsprechen
   * @param label  Label das in der Spaltenüberschrift angezeigt wird
   * @param fieldType  Datentyp des Feldes [text, memo, html, int, double, money, date, boolean, ddate, list]
   * @param width  Breite der Spalte; Spaltenbreiten sind fix
   */
  public FxTableField(String fieldName, String label, int fieldType, Double width) {
    if (fieldType<1 || fieldType>10) {
      throw new IllegalArgumentException("falscher Feldtyp");
    }
    this.fieldName = fieldName;
    this.label = label;
    this.fieldType = fieldType;
    this.width = width;
    this.pvf = new PropertyValueFactory(fieldName);
  }

  public String getFieldName() {
    return fieldName;
  }

  public String getLabel() {
    return label;
  }

  public int getFieldType() {
    return fieldType;
  }

  public Double getWidth() {
    return width;
  }

  public TableColumn getControl() {
    return control;
  }

  public PropertyValueFactory getPvf() {
    return pvf;
  }

  public void setFieldName(String fieldName) {
    this.fieldName = fieldName;
  }

  public void setLabel(String label) {
    this.label = label;
  }

  public void setFieldType(int fieldType) {
    if (fieldType<1 || fieldType>10) {
      throw new IllegalArgumentException("falscher Feldtyp");
    }
    this.fieldType = fieldType;
  }

  public void setWidth(Double width) {
    this.width = width;
  }

  public void setControl(TableColumn control) {
    this.control = control;
  }

  public void setPvf(PropertyValueFactory pvf) {
    this.pvf = pvf;
  }
  
}
